package cn.cttic.order.mapper;

import cn.cttic.order.api.domain.BaseSaleOrder;
import cn.cttic.order.api.domain.vo.BaseSaleOrderVo;
import cn.cttic.common.mybatis.core.mapper.BaseMapperPlus;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 销售订单Mapper接口
 *
 * @author Times.Studio
 * @date 2024-09-17
 */
public interface BaseSaleOrderMapper extends BaseMapperPlus<BaseSaleOrder, BaseSaleOrderVo> {

    @Select("<script>" +
        "SELECT\n" +
        "	dictCH.dict_label AS channelName,\n" +
        "	company.company_name AS companyName,\n" +
        "	saleOrder.*,\n" +
        "	CONCAT(saleOrder.last_name, IF (saleOrder.gender = 0, '先生', IF(saleOrder.gender = 1, '女士', ''))) as fullName,\n" +
        "	product.product_name AS productName,\n" +
        "	oss.url AS productThumbnailUrl,\n" +
        "	device.device_name AS deviceName,\n" +
        "	device.device_model AS deviceModel,\n" +
        "	person.real_name AS salesManName,\n" +
        "	dictSOS.dict_label AS statusName \n" +
        "FROM\n" +
        "	base_sale_order saleOrder\n" +
        "	INNER JOIN base_user bu ON bu.id = saleOrder.sales_man_id and bu.del_flag = 0\n" +
        "	INNER JOIN base_person person ON person.id = bu.person_id and person.del_flag = 0\n" +
        "	INNER JOIN base_company company ON company.id = bu.company_id and company.del_flag = 0\n" +
        "	INNER JOIN base_product product ON product.id = saleOrder.product_id and product.del_flag = 0\n" +
        "	INNER JOIN sys_oss oss ON oss.oss_id = product.product_thumbnail\n" +
        "	INNER JOIN base_device device ON device.id = product.device_id and device.del_flag = 0\n" +
        "	INNER JOIN sys_dict_data dictCH ON dictCH.dict_type = 'dict_channel_type' \n" +
        "	AND dictCH.dict_value = company.channel_type\n" +
        "	INNER JOIN sys_dict_data dictSOS ON dictSOS.dict_type = 'dict_sale_order_status' \n" +
        "	AND dictSOS.dict_value = saleOrder.`status`\n" +
        "${ew.customSqlSegment}" +
        "</script>")
    public Page<BaseSaleOrderVo> getSaleOrderPageList(Page Page, @Param(Constants.WRAPPER) QueryWrapper queryWrapper);

    @Select("<script>" +
        "SELECT\n" +
        "	dictCH.dict_label AS channelName,\n" +
        "	company.company_name AS companyName,\n" +
        "	saleOrder.*,\n" +
        "	CONCAT(saleOrder.last_name, IF (saleOrder.gender = 0, '先生', IF(saleOrder.gender = 1, '女士', ''))) as fullName,\n" +
        "	product.product_name AS productName,\n" +
        "	oss.url AS productThumbnailUrl,\n" +
        "	device.device_name AS deviceName,\n" +
        "	device.device_model AS deviceModel,\n" +
        "	person.real_name AS salesManName,\n" +
        "	dictSOS.dict_label AS statusName \n" +
        "FROM\n" +
        "	base_sale_order saleOrder\n" +
        "	INNER JOIN base_user bu ON bu.id = saleOrder.sales_man_id and bu.del_flag = 0\n" +
        "	INNER JOIN base_person person ON person.id = bu.person_id and person.del_flag = 0\n" +
        "	INNER JOIN base_company company ON company.id = bu.company_id and company.del_flag = 0\n" +
        "	INNER JOIN base_product product ON product.id = saleOrder.product_id and product.del_flag = 0\n" +
        "	INNER JOIN sys_oss oss ON oss.oss_id = product.product_thumbnail\n" +
        "	INNER JOIN base_device device ON device.id = product.device_id and device.del_flag = 0\n" +
        "	INNER JOIN sys_dict_data dictCH ON dictCH.dict_type = 'dict_channel_type' \n" +
        "	AND dictCH.dict_value = company.channel_type\n" +
        "	INNER JOIN sys_dict_data dictSOS ON dictSOS.dict_type = 'dict_sale_order_status' \n" +
        "	AND dictSOS.dict_value = saleOrder.`status`\n" +
        "WHERE\n" +
        "   saleOrder.id = #{orderId}" +
        "</script>")
    public BaseSaleOrderVo getSaleOrderInfo(@Param(value = "orderId") String orderId);


}
